/* eslint-disable */
import _m0 from "protobufjs/minimal";
import { Visibility } from "./common";

export const protobufPackage = "slash.store";

export enum WorkspaceSettingKey {
  WORKSPACE_SETTING_KEY_UNSPECIFIED = 0,
  /** WORKSPACE_SETTING_LICENSE_KEY - The license key. */
  WORKSPACE_SETTING_LICENSE_KEY = 1,
  /** WORKSPACE_SETTING_SECRET_SESSION - The secret session key used to encrypt session data. */
  WORKSPACE_SETTING_SECRET_SESSION = 2,
  /** WORKSAPCE_SETTING_ENABLE_SIGNUP - Whether to enable other users to sign up. */
  WORKSAPCE_SETTING_ENABLE_SIGNUP = 3,
  /** WORKSPACE_SETTING_CUSTOM_STYLE - The custom style. */
  WORKSPACE_SETTING_CUSTOM_STYLE = 4,
  /** WORKSPACE_SETTING_CUSTOM_SCRIPT - The custom script. */
  WORKSPACE_SETTING_CUSTOM_SCRIPT = 5,
  /** WORKSPACE_SETTING_AUTO_BACKUP - The auto backup setting. */
  WORKSPACE_SETTING_AUTO_BACKUP = 6,
  /** WORKSPACE_SETTING_INSTANCE_URL - The instance URL. */
  WORKSPACE_SETTING_INSTANCE_URL = 7,
  /** WORKSPACE_SETTING_DEFAULT_VISIBILITY - The default visibility of shortcuts and collections. */
  WORKSPACE_SETTING_DEFAULT_VISIBILITY = 8,
  UNRECOGNIZED = -1,
}

export interface WorkspaceSetting {
  key: WorkspaceSettingKey;
  /** The license key of workspace. */
  licenseKey?:
    | string
    | undefined;
  /** The secret session key used to encrypt session data. */
  secretSession?:
    | string
    | undefined;
  /** Whether to enable other users to sign up. */
  enableSignup?:
    | boolean
    | undefined;
  /** The custom style. */
  customStyle?:
    | string
    | undefined;
  /** The custom script. */
  customScript?:
    | string
    | undefined;
  /** The auto backup setting. (Unimplemented) */
  autoBackup?:
    | AutoBackupWorkspaceSetting
    | undefined;
  /** The instance URL of workspace. */
  instanceUrl?:
    | string
    | undefined;
  /** The default visibility of shortcuts and collections. */
  defaultVisibility?: Visibility | undefined;
}

export interface AutoBackupWorkspaceSetting {
  /** Whether auto backup is enabled. */
  enabled: boolean;
  /**
   * The cron expression for auto backup.
   * For example, "0 0 0 * * *" means backup at 00:00:00 every day.
   * See https://en.wikipedia.org/wiki/Cron for more details.
   */
  cronExpression: string;
  /** The maximum number of backups to keep. */
  maxKeep: number;
}

function createBaseWorkspaceSetting(): WorkspaceSetting {
  return {
    key: 0,
    licenseKey: undefined,
    secretSession: undefined,
    enableSignup: undefined,
    customStyle: undefined,
    customScript: undefined,
    autoBackup: undefined,
    instanceUrl: undefined,
    defaultVisibility: undefined,
  };
}

export const WorkspaceSetting = {
  encode(message: WorkspaceSetting, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.key !== 0) {
      writer.uint32(8).int32(message.key);
    }
    if (message.licenseKey !== undefined) {
      writer.uint32(18).string(message.licenseKey);
    }
    if (message.secretSession !== undefined) {
      writer.uint32(26).string(message.secretSession);
    }
    if (message.enableSignup !== undefined) {
      writer.uint32(32).bool(message.enableSignup);
    }
    if (message.customStyle !== undefined) {
      writer.uint32(42).string(message.customStyle);
    }
    if (message.customScript !== undefined) {
      writer.uint32(50).string(message.customScript);
    }
    if (message.autoBackup !== undefined) {
      AutoBackupWorkspaceSetting.encode(message.autoBackup, writer.uint32(58).fork()).ldelim();
    }
    if (message.instanceUrl !== undefined) {
      writer.uint32(66).string(message.instanceUrl);
    }
    if (message.defaultVisibility !== undefined) {
      writer.uint32(72).int32(message.defaultVisibility);
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): WorkspaceSetting {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseWorkspaceSetting();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 8) {
            break;
          }

          message.key = reader.int32() as any;
          continue;
        case 2:
          if (tag !== 18) {
            break;
          }

          message.licenseKey = reader.string();
          continue;
        case 3:
          if (tag !== 26) {
            break;
          }

          message.secretSession = reader.string();
          continue;
        case 4:
          if (tag !== 32) {
            break;
          }

          message.enableSignup = reader.bool();
          continue;
        case 5:
          if (tag !== 42) {
            break;
          }

          message.customStyle = reader.string();
          continue;
        case 6:
          if (tag !== 50) {
            break;
          }

          message.customScript = reader.string();
          continue;
        case 7:
          if (tag !== 58) {
            break;
          }

          message.autoBackup = AutoBackupWorkspaceSetting.decode(reader, reader.uint32());
          continue;
        case 8:
          if (tag !== 66) {
            break;
          }

          message.instanceUrl = reader.string();
          continue;
        case 9:
          if (tag !== 72) {
            break;
          }

          message.defaultVisibility = reader.int32() as any;
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  create(base?: DeepPartial<WorkspaceSetting>): WorkspaceSetting {
    return WorkspaceSetting.fromPartial(base ?? {});
  },

  fromPartial(object: DeepPartial<WorkspaceSetting>): WorkspaceSetting {
    const message = createBaseWorkspaceSetting();
    message.key = object.key ?? 0;
    message.licenseKey = object.licenseKey ?? undefined;
    message.secretSession = object.secretSession ?? undefined;
    message.enableSignup = object.enableSignup ?? undefined;
    message.customStyle = object.customStyle ?? undefined;
    message.customScript = object.customScript ?? undefined;
    message.autoBackup = (object.autoBackup !== undefined && object.autoBackup !== null)
      ? AutoBackupWorkspaceSetting.fromPartial(object.autoBackup)
      : undefined;
    message.instanceUrl = object.instanceUrl ?? undefined;
    message.defaultVisibility = object.defaultVisibility ?? undefined;
    return message;
  },
};

function createBaseAutoBackupWorkspaceSetting(): AutoBackupWorkspaceSetting {
  return { enabled: false, cronExpression: "", maxKeep: 0 };
}

export const AutoBackupWorkspaceSetting = {
  encode(message: AutoBackupWorkspaceSetting, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
    if (message.enabled === true) {
      writer.uint32(8).bool(message.enabled);
    }
    if (message.cronExpression !== "") {
      writer.uint32(18).string(message.cronExpression);
    }
    if (message.maxKeep !== 0) {
      writer.uint32(24).int32(message.maxKeep);
    }
    return writer;
  },

  decode(input: _m0.Reader | Uint8Array, length?: number): AutoBackupWorkspaceSetting {
    const reader = input instanceof _m0.Reader ? input : _m0.Reader.create(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseAutoBackupWorkspaceSetting();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          if (tag !== 8) {
            break;
          }

          message.enabled = reader.bool();
          continue;
        case 2:
          if (tag !== 18) {
            break;
          }

          message.cronExpression = reader.string();
          continue;
        case 3:
          if (tag !== 24) {
            break;
          }

          message.maxKeep = reader.int32();
          continue;
      }
      if ((tag & 7) === 4 || tag === 0) {
        break;
      }
      reader.skipType(tag & 7);
    }
    return message;
  },

  create(base?: DeepPartial<AutoBackupWorkspaceSetting>): AutoBackupWorkspaceSetting {
    return AutoBackupWorkspaceSetting.fromPartial(base ?? {});
  },

  fromPartial(object: DeepPartial<AutoBackupWorkspaceSetting>): AutoBackupWorkspaceSetting {
    const message = createBaseAutoBackupWorkspaceSetting();
    message.enabled = object.enabled ?? false;
    message.cronExpression = object.cronExpression ?? "";
    message.maxKeep = object.maxKeep ?? 0;
    return message;
  },
};

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

export type DeepPartial<T> = T extends Builtin ? T
  : T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
  : T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
  : Partial<T>;
